package com.example.tenant.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tenant.entity.SysTenant;
import com.example.tenant.mapper.SysTenantMapper;
import com.example.tenant.service.SysTenantService;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;

import java.io.FileOutputStream;

/**
 * 行政区划
 *
 * @author waterx
 * @date 2024-02-16 22:40:06
 */
@Service
public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant> implements SysTenantService {

    @SneakyThrows
    @Override
    public void export(Long tenantId, FileOutputStream outputStream) {
        try (ExcelWriter excelWriter = EasyExcel.write(outputStream, entityClass).build()) {
            // 创建工作表
            WriteSheet writeSheet = EasyExcel.writerSheet("sheet").build();
            // 写入数据
            excelWriter.write(this.list(new LambdaQueryWrapper<SysTenant>().eq(SysTenant::getId, tenantId)), writeSheet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
